class Solution03 {
	public TreeNode inorderSuccessor(TreeNode root, TreeNode p){
		if(root == null || p == null){
			return null;
		}

		TreeNode curNode = root;
		TreeNode resNode = null;
		while(curNode != null){
			if(curNode.val > p.val){
				// 找到大于p.val中最小的节点(第一个大于)
				resNode = curNode;
				curNode = curNode.left;
			} else {
				// 小于等于在右子树中查找
				curNode = curNode.right;
			}
		}
		return resNode;
	}
}
